package cn.com.headfree.point.service.impl;

import cn.com.headfree.entity.TPersonYearPointDetail;
import cn.com.headfree.point.dao.ISalaryUserDataInfoDao;
import cn.com.headfree.point.dao.RuleElementDao;
import cn.com.headfree.point.service.ISalaryBusinessBindService;
import cn.com.headfree.point.service.ISalaryUserDataInfoService;
import cn.com.headfree.salary.service.IUserDataInfoService;
import cn.com.headfree.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @Description: TODO
 * @Author wcSun
 * @Date 2021/6/22
 **/
@Service("salaryUserDataInfoService")
@Transactional
public class SalaryUserDataInfoServiceImpl implements ISalaryUserDataInfoService {

    // 年度绩效
    @Value("${t_year_effect_info}")
    private String t_year_effect_info;
    // 学历信息
    @Value("${t_educate_info}")
    private String t_educate_info;
    // 专业技术资格
    @Value("${t_pro_tec_info}")
    private String t_pro_tec_info;
    // 技能等级信息
    @Value("${t_skill_level_info}")
    private String t_skill_level_info;
    // 专家人才称号
    @Value("${t_expert_title_info}")
    private String t_expert_title_info;
    // 学术成果
    @Value("${t_acade_achive_info}")
    private String t_acade_achive_info;
    // 专利信息
    @Value("${t_patent_info}")
    private String t_patent_info;
    // 技艺革新信息
    @Value("${t_tec_innov_info}")
    private String t_tec_innov_info;
    // 竞赛考试信息
    @Value("${t_contest_info}")
    private String t_contest_info;
    // 科技管理及创新成果
    @Value("${t_tec_man_innov}")
    private String t_tec_man_innov;
    // 个人荣誉
    @Value("${t_honor_info}")
    private String t_honor_info;
    // 員工流動
    @Value("${t_employee_mobility}")
    private String t_employee_mobility;
    // 技术标准
    @Value("${t_tec_standard_info}")
    private String t_tec_standard_info;
    // 工龄
    @Value("${t_employ_length}")
    private String t_employ_length;

//    @Autowired
//    private ISalaryUserDataInfoDao salaryUserDataInfoDao;

    @Autowired
    private IUserDataInfoService userDataInfoService;

    @Autowired
    private ISalaryBusinessBindService salaryBusinessBindService;

    @Override
    public void salaryUserDataInfoByPointDetail(TPersonYearPointDetail personYearPointDetail) {
        String erpNo = personYearPointDetail.getErpNo();
        String salaryId = personYearPointDetail.getSalaryId();
        int year = personYearPointDetail.getYear();
        //学历信息
        List<EducateInfoVo> educateInfos = userDataInfoService.getEducateInfoByErpNo(erpNo, salaryId, year);
        if(!CollectionUtils.isEmpty(educateInfos)){
            educateInfos.stream().forEach(item ->{
                salaryBusinessBind(salaryId,t_educate_info,item.getId());
            });
        }

        //专业技术资格
        List<ProTecInfoVo> proTecInfos = userDataInfoService.getProTecInfoByErpNo(erpNo, salaryId, t_pro_tec_info,
                personYearPointDetail.getRuleId(), year, personYearPointDetail.getOrgId());
        if(!CollectionUtils.isEmpty(proTecInfos)){
            proTecInfos.stream().forEach(item ->{
                salaryBusinessBind(salaryId,t_pro_tec_info,item.getId());
            });
        }

        //技能等级
        List<SkillLevelInfoVo> skillLevelInfos = userDataInfoService.getSkillLevelInfoByErpNo(erpNo, salaryId,
                t_skill_level_info, personYearPointDetail.getRuleId(), year, personYearPointDetail.getOrgId());
        if(!CollectionUtils.isEmpty(skillLevelInfos)) {
            skillLevelInfos.stream().forEach(item -> {
                salaryBusinessBind(salaryId, t_skill_level_info, item.getId());
            });
        }

        //专家人才称号
        List<ExpertTitleVo> expertTitleInfos = userDataInfoService.getExpertTitleInfoByErpNo(erpNo, salaryId,
                t_expert_title_info, personYearPointDetail.getRuleId(), year, personYearPointDetail.getOrgId());
        if(!CollectionUtils.isEmpty(expertTitleInfos)) {
            expertTitleInfos.stream().forEach(item -> {
                salaryBusinessBind(salaryId, t_expert_title_info, item.getId());
            });
        }

        //学术成果
        List<AcadeAchiveVo> acadeAchiveVos = userDataInfoService.getAcadeAchiveInfoByErpNo(erpNo, salaryId,
                t_acade_achive_info, personYearPointDetail.getRuleId(), year, personYearPointDetail.getOrgId());
        if(!CollectionUtils.isEmpty(acadeAchiveVos)) {
            acadeAchiveVos.stream().forEach(item -> {
                salaryBusinessBind(salaryId, t_acade_achive_info, item.getId());
            });
        }

        //发明专利
        List<PatentInfoVo> patentInfos = userDataInfoService.getPatentInfoByErpNo(erpNo, salaryId, t_patent_info,
                personYearPointDetail.getRuleId(), year, personYearPointDetail.getOrgId());
        if(!CollectionUtils.isEmpty(patentInfos)) {
            patentInfos.stream().forEach(item -> {
                salaryBusinessBind(salaryId, t_patent_info, item.getId());
            });
        }

        //科技管理创新
        List<TecManInnovVo> tecManInnovVos = userDataInfoService.getTecManInnovByErpNo(erpNo, salaryId,
                t_tec_man_innov, personYearPointDetail.getRuleId(), year, personYearPointDetail.getOrgId());
        if(!CollectionUtils.isEmpty(tecManInnovVos)) {
            tecManInnovVos.stream().forEach(item -> {
                salaryBusinessBind(salaryId, t_tec_man_innov, item.getId());
            });
        }

        //技艺革新
        List<TecInnovInfoVo> tecInnovInfoVos = userDataInfoService.getTecInnovInfoByErpNo(erpNo, salaryId,
                t_tec_innov_info, personYearPointDetail.getRuleId(), year, personYearPointDetail.getOrgId());
        if(!CollectionUtils.isEmpty(tecInnovInfoVos)) {
            tecInnovInfoVos.stream().forEach(item -> {
                salaryBusinessBind(salaryId, t_tec_innov_info, item.getId());
            });
        }

        //专业竞赛考试
        List<ContestInfoVo> tContestInfos = userDataInfoService.getContestInfoByErpNo(erpNo, salaryId,
                t_contest_info, personYearPointDetail.getRuleId(), year, personYearPointDetail.getOrgId());
        if(!CollectionUtils.isEmpty(tContestInfos)) {
            tContestInfos.stream().forEach(item -> {
                salaryBusinessBind(salaryId, t_contest_info, item.getId());
            });
        }

        //个人荣誉
        List<HonorDatasVo> honorDatasVos = userDataInfoService.getHonnorInfoByErpNo(erpNo, salaryId, t_honor_info,
                personYearPointDetail.getRuleId(), year, personYearPointDetail.getOrgId());
        if(!CollectionUtils.isEmpty(honorDatasVos)) {
            honorDatasVos.stream().forEach(item -> {
                salaryBusinessBind(salaryId, t_honor_info, item.getId());
            });
        }

        //技术标准
        List<TecStandardVo> tecStandardInfoVos = userDataInfoService.getTecStandardInfoByErpNo(erpNo, salaryId,
                t_tec_standard_info, personYearPointDetail.getRuleId(), year, personYearPointDetail.getOrgId());
        if(!CollectionUtils.isEmpty(tecStandardInfoVos)) {
            tecStandardInfoVos.stream().forEach(item -> {
                salaryBusinessBind(salaryId, t_tec_standard_info, item.getId());
            });
        }

        //年度绩效
        List<YearEffectVo> yearEffectVos = userDataInfoService.getYearEffectByErpNo(erpNo, t_year_effect_info,
                personYearPointDetail.getRuleId(), year, personYearPointDetail.getOrgId());
        if(!CollectionUtils.isEmpty(yearEffectVos)) {
            yearEffectVos.stream().forEach(item -> {
                salaryBusinessBind(salaryId, t_year_effect_info, item.getId());
            });
        }

        //员工流动
        List<TEmployeeMobilityVo> employeeMobilities = userDataInfoService.getEmployeeMobilityByErpNo(erpNo,
                salaryId, t_employee_mobility, personYearPointDetail.getRuleId(), year, personYearPointDetail.getOrgId());
        if(!CollectionUtils.isEmpty(employeeMobilities)) {
            employeeMobilities.stream().forEach(item -> {
                salaryBusinessBind(salaryId, t_employee_mobility, item.getId());
            });
        }

    }


    public void salaryBusinessBind(String salaryId,String businessTypeId,String itemId){
        if (CollectionUtils.isEmpty(salaryBusinessBindService.selectSalaryBusinessBindByItem(salaryId,businessTypeId,itemId))){
            salaryBusinessBindService.saveSalaryBusinessBindByItem(salaryId,businessTypeId,itemId);
        }
    }
}
